#include <iostream>
#include <algorithm>

using namespace std;

const int N = 1e6 + 10;

int n;
struct node
{
	int l, r;
}a[N];

//按照区间左端点升序排列
bool cmp(node x, node y)
{
	return x.l < y.l;
}

int main()
{
	cin >> n;
	for(int i = 1; i <= n; i++) cin >> a[i].l >> a[i].r;

	//1.先按照左端点升序排序
	sort(a + 1, a + 1 + n, cmp);

	//2.当区间重叠时，尽可能保留右端点小的区间
	int ret = 1;
	int r = a[1].r; // 以第一个区间为基准，向后选择
	for(int i = 2; i <= n; i++)
	{
		int left = a[i].l, right = a[i].r;
		if(left < r) // 有重叠
		{
			r = min(r, right); // 取右端点小的那个
		}
		else 
		{
			ret++;
			r = right; // r等于新的右区间
		}
	}

	cout << ret << endl;

	return 0;
}

